<template>
  <div>
    <el-dialog
      :title="doEdit?'操作':'查看'"
      :visible.sync="dialogVisible"
      width="80%"
      v-if="company&&formData"
      @close="close"
    >
      <el-tabs v-model="tabIndex">
        <el-tab-pane label="申请信息" name="0">
          <el-row style="margin:8px 0px;">
            <el-col :sm="4" style="text-align: right;padding-right: 15px;">单位名称:</el-col>
            <el-col :sm="20" style="color: #999;">测试单位</el-col>
          </el-row>
          <el-row style="margin:8px 0px;">
            <el-col :sm="4" style="text-align: right;padding-right: 15px;">编办文件</el-col>
            <el-col :sm="20">
              <a :href="serverProjectName+formData.bzwjurl" target="blank">查看</a>
            </el-col>
          </el-row>
          <el-row style="margin:8px 0px;">
            <el-col :sm="4" style="text-align: right;padding-right: 15px;">附件</el-col>
            <el-col :sm="20">
              <a :href="serverProjectName+formData.fileurl">查看</a>
            </el-col>
          </el-row>
          <el-row style="margin:8px 0px;">
            <el-col :sm="4" style="text-align: right;padding-right: 15px;">申请原因</el-col>
            <el-col :sm="20">{{formData.mark}}</el-col>
          </el-row>

          <el-row style="margin:8px 0px;">
            <el-col :sm="4" style="text-align: right;padding-right: 15px;">历史流程</el-col>
            <el-col :sm="20">
              <el-table :data="history" style="width: 100%" size="mini" border>
                <el-table-column prop="taskName" label="步骤" align="center"></el-table-column>
                <el-table-column prop="userName" label="审核人" align="center"></el-table-column>
                <el-table-column prop="mobile" label="电话" align="center"></el-table-column>
                <el-table-column prop="mark" label="审批意见" align="center"></el-table-column>
                <el-table-column prop="passStr" label="状态" align="center"></el-table-column>
                <el-table-column prop="optime" label="操作时间" align="center"></el-table-column>
              </el-table>
            </el-col>
          </el-row>
          <h4 class="hbg" v-if="doEdit&&opData.formKey!='carbz_jbrxg'">审核</h4>
          <el-form style="padding: 20px;" v-if="doEdit&&opData.formKey!='carbz_jbrxg'">
            <el-row>
              <el-col :sm="24">
                <el-form-item label="是否批准">
                  <el-radio-group v-model="pass">
                    <el-radio :label="1">批准</el-radio>
                    <el-radio :label="0">不批准</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin-top: 10px;">
              <el-col :sm="24">
                <el-form-item label="备注">
                  <el-input v-model="formData.shenhemark" type="textarea" placeholder="请输入备注"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-row v-if="doEdit&&opData.formKey!='carbz_jbrxg'">
            <el-col :sm="24" style="padding-left: 20px;">
              <el-button type="primary" @click="save">保存</el-button>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="单位信息" name="1" class="smallform">
          <el-form label-width="100px">
            <h4 class="hbg mt0">基本信息</h4>
            <el-row>
              <el-col :sm="8">
                <el-form-item label="单位名称" prop1="companyName">{{company.companyName}}</el-form-item>
              </el-col>
              <el-col :sm="8">
                <el-form-item label="单位编码" prop1="companyCode">{{company.companyCode}}</el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :sm="8">
                <el-form-item
                  label="隶属类别"
                  prop1="subLevId"
                >{{company.subLevId>0?lishuleibie[company.subLevId-1].name:""}}</el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :sm="8">
                <el-form-item label="隶属类型">{{company.tagName}}</el-form-item>
              </el-col>
              <el-col :sm="8">
                <el-form-item label="上级单位">{{company.parentName}}</el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :sm="8">
                <el-form-item label="单位规格">{{company.standardName}}</el-form-item>
              </el-col>
              <el-col :sm="8">
                <el-form-item label="单位性质">{{company.propName}}</el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :sm="8">
                <el-form-item label="联系地址">{{company.address}}</el-form-item>
              </el-col>
              <el-col :sm="8">
                <el-form-item label="紧急联系人">{{company.linkMan}}</el-form-item>
              </el-col>
              <el-col :sm="8">
                <el-form-item label="紧急联系电话">{{company.mobile}}</el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :sm="24">
                <el-form-item label="备注信息">{{company.reMark}}</el-form-item>
              </el-col>
            </el-row>
            <h4 class="hbg mt0">人员信息</h4>
            <el-row class="smallform">
              <el-col :sm="4">
                <el-form-item label="单位实有人数">{{company.dwsynum}}</el-form-item>
              </el-col>
              <el-col :sm="4">
                <el-form-item label="单位编制人数">{{company.rybznum}}</el-form-item>
              </el-col>
              <el-col :sm="4">
                <el-form-item label="定向化岗位人数">{{company.dxhgwnum}}</el-form-item>
              </el-col>
              <el-col :sm="4">
                <el-form-item label="离休干部人数">{{company.lxgbnum}}</el-form-item>
              </el-col>
              <el-col :sm="4">
                <el-form-item label="退休干部人数">{{company.txgbnum}}</el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :sm="4">
                <el-form-item label="在职正省">{{company.zzzsnum}}</el-form-item>
              </el-col>
              <el-col :sm="8" style="padding-left: 10px;">{{company.zzzsnums}}</el-col>
              <el-col :sm="4">
                <el-form-item label="在职副省">{{company.zzfsnum}}</el-form-item>
              </el-col>
              <el-col :sm="8" style="padding-left: 10px;">{{company.zzfsnums}}</el-col>
            </el-row>
            <el-row>
              <el-col :sm="4">
                <el-form-item label="离休正省">{{company.lxzsnum}}</el-form-item>
              </el-col>
              <el-col :sm="8" style="padding-left: 10px;">{{company.lxzsnums}}</el-col>
              <el-col :sm="4">
                <el-form-item label="离休副省">{{company.lxfsnum}}</el-form-item>
              </el-col>
              <el-col :sm="8" style="padding-left: 10px;">{{company.lxfsnums}}</el-col>
            </el-row>
            <el-row>
              <el-col :sm="4">
                <el-form-item label="退休正省">{{company.txzsnum}}</el-form-item>
              </el-col>
              <el-col :sm="8" style="padding-left: 10px;">{{company.txzsnums}}</el-col>
              <el-col :sm="4">
                <el-form-item label="退休副省">{{company.txfsnum}}</el-form-item>
              </el-col>
              <el-col :sm="8" style="padding-left: 10px;">{{company.txfsnums}}</el-col>
            </el-row>
          </el-form>

          <el-table
            :data="cars"
            style="width: 100%"
            :border="true"
            :header-cell-style="{background:'#F5F7FA'}"
          >
            <el-table-column prop="nature" label="车辆性质"></el-table-column>
            <el-table-column prop="ZZSJGBYC" label="在职省级干部用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.ZZSJGBYC" />
                </div>
                <div v-else>{{scope.row.ZZSJGBYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="LTXZSJGBYC" label="离退休正省级干部用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.LTXZSJGBYC" />
                </div>
                <div v-else>{{scope.row.LTXZSJGBYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="LXFSJGBYC" label="离休副省级干部用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.LXFSJGBYC" />
                </div>
                <div v-else>{{scope.row.LXFSJGBYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="TXFSJGBYC" label="退休副省级干部用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.TXFSJGBYC" />
                </div>
                <div v-else>{{scope.row.TXFSJGBYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="DXHSWGWYC" label="定向化实物保障岗位用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.DXHSWGWYC" />
                </div>
                <div v-else>{{scope.row.DXHSWGWYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="JYTXYC" label="机要通信用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.JYTXYC" />
                </div>
                <div v-else>{{scope.row.JYTXYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="YJBZYC" label="应急用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.YJBZYC" />
                </div>
                <div v-else>{{scope.row.YJBZYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="JYTXYYJHYYC" label="机要通信与应急合一用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.JYTXYYJHYYC" />
                </div>
                <div v-else>{{scope.row.JYTXYYJHYYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="LTXGBGLJGYC" label="离退休干部管理机构用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.LTXGBGLJGYC" />
                </div>
                <div v-else>{{scope.row.LTXGBGLJGYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="DYSCDCYC" label="调研视察督察用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.DYSCDCYC" />
                </div>
                <div v-else>{{scope.row.DYSCDCYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="ZWJDYC" label="政务接待用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.ZWJDYC" />
                </div>
                <div v-else>{{scope.row.ZWJDYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="ZFZQYC" label="执法执勤用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.ZFZQYC" />
                </div>
                <div v-else>{{scope.row.ZFZQYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="TZZYJSYC" label="特种专业技术用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.TZZYJSYC" />
                </div>
                <div v-else>{{scope.row.TZZYJSYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="YWYC" label="业务用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.YWYC" />
                </div>
                <div v-else>{{scope.row.YWYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="BC" label="班车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.BC" />
                </div>
                <div v-else>{{scope.row.BC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="HQFWYC" label="后勤服务用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.HQFWYC" />
                </div>
                <div v-else>{{scope.row.HQFWYC}}</div>
              </template>
            </el-table-column>
            <el-table-column prop="QTYC" label="其他用车" align="center">
              <template slot-scope="scope">
                <div v-if="scope.$index==2">
                  <input type="number" min="0" class="tableInput" v-model="scope.row.QTYC" />
                </div>
                <div v-else>{{scope.row.QTYC}}</div>
              </template>
            </el-table-column>
          </el-table>
          <el-row v-if="doEdit&&opData.formKey=='carbz_jbrxg'">
            <el-col :sm="24" style="margin-top: 20px;text-align: center;">
              <el-button type="primary" @click="save">保存</el-button>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
  </div>
</template>
<script>
import { viewJson, sh, diaodu, xgbz } from "@/api/task";
import { findDetails } from "@/api/company";
import { bz } from "@/api/carbz";
import { listJson } from "@/api/car";
import { listJson as driverListJson } from "@/api/driver";
export default {
  data() {
    return {
      pass: 1,
      jstime: "",
      carId: "",
      jsaddress: "",
      shenhemark: "",
      tabIndex: "0",
      serverProjectName: "",
      opData: null,
      history: [],
      formData: null,
      doEdit: false,
      dialogVisible: false,
      company: null, //单位信息
      lishuleibie: [
        {
          id: 1,
          name: "省直部门及所属单位",
        },
        {
          id: 2,
          name: "市直部门及所属单位",
        },
        {
          id: 3,
          name: "区直部门及所属单位",
        },
        {
          id: 4,
          name: "乡镇级",
        },
      ],
      cars: [
        {
          nature: "实有车辆数目",
          ZZSJGBYC: "0", //在职省级干部用车
          LTXZSJGBYC: "0", //离退休正省级干部用车
          LXFSJGBYC: "0", //离休副省级干部用车
          TXFSJGBYC: "0", //退休副省级干部用车
          DXHSWGWYC: "0", //定向化实物保障岗位用车
          JYTXYC: "0", //机要通信用车
          YJBZYC: "0", //应急用车
          JYTXYYJHYYC: "0", //机要通信与应急合一用车
          LTXGBGLJGYC: "0", //离退休干部管理机构用车
          DYSCDCYC: "0", //调研视察督察用车
          ZWJDYC: "0", //政务接待用车
          ZFZQYC: "0", //执法执勤用车
          TZZYJSYC: "0", //特种专业技术用车
          YWYC: "0", //业务用车
          BC: "0", //班车
          HQFWYC: "0", //后勤服务用车
          QTYC: "0", //其他用车
        },
        {
          nature: "现有编制数目",
          ZZSJGBYC: "0",
          LTXZSJGBYC: "0",
          LXFSJGBYC: "0",
          TXFSJGBYC: "0",
          DXHSWGWYC: "0",
          JYTXYC: "0",
          YJBZYC: "0",
          JYTXYYJHYYC: "0",
          LTXGBGLJGYC: "0",
          DYSCDCYC: "0",
          ZWJDYC: "0",
          ZFZQYC: "0",
          TZZYJSYC: "0",
          YWYC: "0",
          BC: "0",
          HQFWYC: "0",
          QTYC: "0",
        },
        { nature: "修改" },
      ],
    };
  },
  methods: {
    close() {
      this.dialogVisible = false;
    },
    //编辑任务
    editTask(opData) {
      this.viewTask(opData);
      this.doEdit = true;
    },
    async viewTask(opData) {
      this.doEdit = false;
      this.opData = opData;
      this.findDetails();
      this.fetchBzData();
      let params = {
        tableId: opData.tableId,
        pid: opData.processInstanceId,
        taskId: opData.taskId,
        formKey: opData.formKey,
      };
      let r = await viewJson(params);
      this.formData = r.carbz;
      this.history.splice(0, this.history.length, ...r.history);
      if (this.opData.formKey == "carbz_jbrxg") {
        this.tabIndex = "1";
      } else {
        this.tabIndex = "0";
      }
      this.dialogVisible = true;
    },
    //获取单位信息
    async findDetails(id) {
      let params = { id: this.opData.reqComId };
      let data = await findDetails(params);
      if (data.error == 1) {
        this.$message.error("系统出错");
      } else {
        data.company.reMark = data.company.reMark ? data.company.reMark : "";
        data.company.subLevId =
          data.company.subLevId != "0" ? data.company.subLevId : null;
        data.company.tagId =
          data.company.tagId != "0" ? data.company.tagId : null;
        data.company.parentId =
          data.company.parentId != "0" ? data.company.parentId : null;
        data.company.standardId =
          data.company.standardId != "0" ? data.company.standardId : null;
        data.company.properId =
          data.company.properId != "0" ? data.company.properId : null;
        if (data.company.standardId) {
          data.gg.forEach((e) => {
            if (e.id == data.company.standardId) {
              data.company.standardName = e.name;
            }
          });
        }
        this.company = data.company;
      }
    },
    ///获取本单位到车辆信息
    async fetchBzData() {
      let params = { companyid: this.opData.reqComId };
      let data = await bz(params);
      let newConfig = {};
      for (let key in data.bz) {
        let newkey = key.toUpperCase();
        newConfig[newkey] = data.bz[key];
      }
      console.log(newConfig);
      for (let key in this.cars[0]) {
        let realkey = key + "SY";
        if (typeof newConfig[realkey] != "undefined") {
          this.cars[0][key] = newConfig[realkey];
        }
      }
      for (let key in this.cars[1]) {
        let realkey = key + "BZ";
        if (typeof newConfig[realkey] != "undefined") {
          this.cars[1][key] = newConfig[realkey];
          if (this.cars[2]) this.cars[2][key] = newConfig[realkey];
        }
      }
      if (this.opData.formKey != "carbz_jbrxg") {
        this.cars.splice(2, 1);
      }
    },
    //提交用户信息表单
    save() {
      let param = {};
      param["pass"] = this.pass ? "true" : "false";
      param["mark"] = this.formData.shenhemark || "";
      param["tableId"] = this.opData.tableId;
      param["taskId"] = this.opData.taskId;
      param["formKey"] = this.opData.formKey;
      param["pid"] = this.opData.processInstanceId;
      let url = "";
      if (
        this.opData.formKey == "carbz_fzrqr" ||
        this.opData.formKey == "carbz_jbrsp"
      ) {
        this.sh(param);
      } else if (this.opData.formKey == "carbz_jbrxg") {
        let counts = [];
        for (let key in this.cars[2]) {
          if (key == "nature") continue;
          counts.push(this.cars[2][key]);
        }
        console.log(counts);
        let countsStr = counts
          .map(function (e) {
            return e == "" ? 0 : e;
          })
          .join(",");
        param["counts"] = countsStr;
        this.xgbz(param);
      }
    },
    //审核
    async sh(params) {
      let d = await sh(params);
      if (d.error == 0) {
        this.$message("操作成功");
        this.finish();
      } else {
        this.$message("操作失败");
      }
    },
    //后面的审核
    async xgbz(params) {
      let d = await xgbz(params);
      if (d.error == 0) {
        this.$message("操作成功");
        this.finish();
      } else {
        this.$message("操作失败");
      }
    },
    //各种操作完成后关闭对话框刷新父组件列表
    finish() {
      this.close();
      this.$parent.fetchData();
    },
  },
};
</script>
<style lang="scss" scoped>
</style>